//
//  DXWelcomeController.swift
//  新浪微博
//
//  Created by dix on 2017/2/5.
//  Copyright © 2017年 dix. All rights reserved.
//

import UIKit
import SDWebImage
class DXWelcomeController: UIViewController {

    override func loadView() {
        view = bgImageView
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        //设置动画
        /*
         withDuration - 动画时长
         delay - 延迟时间
         Damping - 阻尼系数
         Velocity  - 起始速度
         options - 选项
         */
        UIView.animate(withDuration: 2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {()->() in
            self.headImageView.snp_updateConstraints(closure: { (make) in
                make.top.equalTo(self.view).offset(100)
            })
            //刷新UI
            self.view.layoutIfNeeded()
        }, completion: {(_)->() in
            //动画完成以后
            UIView.animate(withDuration: 0.25, animations: { 
                self.messageLabel.alpha = 1
            }, completion: { (_) in
                //发送通知切换更控制器
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: SWITCHROOTVIEWCONTROLLERNOTI), object: "welcomeVc")
            })
        })
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }
    //设置视图
    private func setupUI(){
        //添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        //添加约束
        headImageView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
        }
        messageLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            make.centerX.equalTo(headImageView)
        }
    }
    //懒加载控件
    private lazy var bgImageView : UIImageView = UIImageView(imgName: "ad_background")
    //用户头像
    private lazy var headImageView : UIImageView = {
        let img = UIImageView(imgName: "avatar_default")
        //圆角
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        img.layer.borderColor = DXThemeColor.cgColor
        img.layer.borderWidth = 1
        img.dx_setImage(urlStr: DXOAuthViewModel.shared.userAccountModel?.avatar_large)
        return img
    }()
    //文字
    private lazy var messageLabel : UILabel = {
        let lab = UILabel()
        lab.text = "jeasonDix"
        //对齐
        lab.textAlignment = .center
        lab.alpha = 0
        return lab
    }()
}
